<?php
function format_size($size) {
	$sizes = array(' Bytes', ' KB', ' MB', ' GB', ' TB', ' PB', ' EB', ' ZB', ' YB');
	if ($size == 0) {
		return 0;
	} else {
		return (round($size/pow(1024, ($i = floor(log($size, 1024)))), 2) . $sizes[$i]);
	}
}

function _conf($keys) {
	if (is_array($keys)) {
		$tmp = $GLOBALS['CONF'];
		foreach($keys as $key) {
			$tmp = $tmp[$key];
		}
		return $tmp;
	} else {
		return $GLOBALS['CONF'][$keys];
	}
}

/**
* Returns the type of the passed var
* - PHP warns against using gettype(), this is my workaround
*
* @param mixed $var
* @return string
*/
function fetchType($var) {
	switch ($var) {
		case is_null($var):
			$type='NULL';
			break;
		case is_bool($var):
			$type='boolean';
			break;
		case is_float($var):
			$type='double';
			break;
		case is_int($var):
			$type='integer';
			break;
		case is_string($var):
			$type='string';
			break;
		case is_array($var):
			$type='array';
			break;
		case is_object($var):
			$type='object';
			break;
		case is_resource($var):
			$type='resource';
			break;
		default:
			$type='unknown type';
			break;
	}
	return $type;
}

